package com.shangbang.verb.controller.recruit;

import com.shangbang.verb.core.BaseResponse;
import com.shangbang.verb.service.recruit.MiddleService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
@Api(value = "发布者和普通用户相关接口", tags = "发布者和普通用户相关接口", description = "发布人和用户之间的操作")

@RestController
@RequestMapping(value = "/recruit/middle")
public class MiddleController {

    @Autowired
    private MiddleService middleService;

    /**
     * 我投递的简历（用户）
     * @param request
     * @param response
     * @param uid
     * @param wordkId
     * @param publishId
     * @return
     */
    @ApiOperation(value = "发布者创建简历接口",notes = "")
    @ApiResponses({ @ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = -1, message = "操作失败") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "wordkId", value = "工作的id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "publishId", value = "发布者id", required = true, dataType = "int")
    })
    @RequestMapping(value = "/deliver", method = {RequestMethod.POST, RequestMethod.GET})
    public BaseResponse deliver(HttpServletRequest request, HttpServletResponse response,
                                 @RequestParam(required = true) Integer uid,
                                 @RequestParam(required = true) Integer wordkId,
                                 @RequestParam(required = true) Integer publishId) {
        Object result = "";
        Integer code = 0;
        String msg = "成功";

        middleService.deliverWork(uid,wordkId,publishId);


        return new BaseResponse(code, msg, result);
    }

    /**
     * 发布者看到的请求列表
     * @param request
     * @param response
     * @param publishId
     * @return
     */
    @ApiOperation(value = "发布者看到的请求列表接口",notes = "当用户为发布者的时候，用户id则为发布者id")
    @ApiResponses({ @ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = -1, message = "操作失败") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "publishId", value = "发布者的id", required = true, dataType = "int")

    })
    @RequestMapping(value = "/partList", method = {RequestMethod.POST, RequestMethod.GET})
    public BaseResponse partList(HttpServletRequest request, HttpServletResponse response,
                                       @RequestParam(required = true) Integer publishId) {
        Object result = "";
        Integer code = 0;
        String msg = "成功";

        result =  middleService.partList(publishId);


        return new BaseResponse(code, msg, result);
    }

    /**
     * 发布者同意用户的请求面试
     * @param request
     * @param response
     * @param middleId
     * @param time
     * @param flag
     * @return
     * @throws ParseException
     */
    @ApiOperation(value = "发布者同意用户的请求面试接口",notes = "")
    @ApiResponses({ @ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = -1, message = "操作失败") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "middleId", value = "发布者的id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "time", value = "预约时间，xxxx-xx-xx :xx:xx:xx", required = true, dataType = "String"),
            @ApiImplicitParam(name = "flag", value = "招聘状态，0：待处理，1：同意，2：不同意", required = true, dataType = "int")

    })
    @RequestMapping(value = "/agreeDelivery", method = {RequestMethod.POST, RequestMethod.GET})
    public BaseResponse agreeDelivery(HttpServletRequest request, HttpServletResponse response,
                                      @RequestParam(required = true) Integer middleId,
                                      @RequestParam(required = true) String time,
                                      @RequestParam(required = true) Integer flag) throws ParseException {
        Object result = "";
        Integer code = 0;
        String msg = "成功";

        middleService.agreeDelivery(middleId,time,flag);


        return new BaseResponse(code, msg, result);
    }

    /**
     *用户查看自己的申请列表
     * @param request
     * @param response
     * @param uid
     * @return
     */
    @ApiOperation(value = "用户查看自己的申请列表",notes = "type是控制当前时间的有无")
    @ApiResponses({ @ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = -1, message = "操作失败") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "page", value = "第几页", required = true, dataType = "int"),
            @ApiImplicitParam(name = "num", value = "每页多少条", required = true, dataType = "int"),
            @ApiImplicitParam(name = "type", value = "type:0 没时间 1：有时间", required = true, dataType = "int")

    })
    @RequestMapping(value = "/myDelivery", method = {RequestMethod.POST, RequestMethod.GET})
    public BaseResponse myDelivery(HttpServletRequest request, HttpServletResponse response,
                                   @RequestParam(required = true) Integer uid,
                                   @RequestParam(required = true) Integer page,
                                   @RequestParam(required = true) Integer type,
                                   @RequestParam(required = true) Integer num)
            throws ParseException {
        //type:0 没时间 1：有时间
        Object result = "";
        Integer code = 0;
        String msg = "成功";

        result = middleService.myDelivery(uid,(page-1)*num,num,type);


        return new BaseResponse(code, msg,result);
    }


}
